Lab 6

Branches

CS211 Lab Policy:

Instructions:

You will create one MATLAB program file named lab6.m for this lab.  For each step below, add appropriate MATLAB code and label each step with appropriate comments.  Make sure you test your code for each step before proceeding to the next step.

After you have competed a "task" below, and it is working correctly, it is suggested that you "comment out" the code for this task. This will decrease the amount of time it takes to test your program for the remaining tasks. (To "comment out" a section of code, highlight the code section using a drag operation with your mouse and then use the "Text" menu, "Comment" command.)

Begin your program by clearing the command window and displaying a brief introduction.

Task 1:

  1. Add code that prompts for and gets the user's age in years.

    Then add code that checks the age entered by the user and displays the following message if the number entered is negative:

    <value entered> is not a valid age, but we will continue.
     

  2. Add code that prompts for and gets the user's squadron, an integer from 1 to 40.

    Then add code that checks the squadron value entered by the user and displays the following message if the number entered is not an integer from 1 to 40:

    <value entered> is not a valid squadron, but we will continue.

    Otherwise, if the number entered is an integer from 1 to 40, your program must display the following message:

    <value entered> is a valid squadron

    Hint:  To check if a number (a double array value) is an integer, check if the number is equal to the floor of itself.  You may use MATLAB's floor() function which truncates a number to an integer.  (Do not use MATLAB's isinteger function which tests for a variable's data type).
     

  3. Using the values entered for age and squadron, display the one message below that accurately describes the relationship between these two values:

    Your age is greater than your squadron number
    Your age is equal to your squadron number
    Your age is less than your squadron number


    Hint: Your code for this step should only use two tests (logical expressions).  Do not include unnecessary tests.
     

Task 2:

The Saffir-Simpson Hurricane Scale categorizes hurricanes by maximum sustained wind speed as shown in the following table.

Wind Speed in MPH

Category

74-96

1

97-111

2

112-131

3

132-155

4

156+

5

  1. Prompt for and get from the user a wind speed in MPH.

  2. Then report the corresponding hurricane category (including not a hurricane) based on the input wind speed followed by a blank line.

Do not include unnecessary tests in your code.
You may assume the user enters a positive integer number. (What would happen if the user entered 96.5?)

Task 3:

  1. Add code that prompts for and gets the user's squadron number.
  2. Based on the value entered for squadron and the briefing schedule shown below, display the following message:

    Squadron <squadron # entered> attends the briefing at <briefing time>.
  Briefing Time     Squadrons   
1600 5, 10, 15, 20, 25, 30, 35
1700 1, 2, 4, 8, 16, 32
1800 3, 6, 9, 12, 18, 21
1900 24, 27, 28, 29, 31, 33, 34
2000 7, 11, 13, 14, 17, 19
2100 all others

If the user entered an invalid squadron number, it is okay to display the briefing time as 2100. 

This problem is best solved with a switch statement.  You could use a multiple-alternative if statement, but the resulting code would be longer and more difficult to read.

Note: If you "commented out" sections of your code, please "uncomment" them before submitting your work. To do this, select the code that is "commented out" and then select the "Text" menu, "Uncomment" command.

Turn-in:

Submit your lab6.m file.